<template>
  <div class="comment-reply-container">
    <van-nav-bar title="暂无回复" class="page-nav-bar">
      <template #left>
        <van-icon name="cross" @click="$emit('closeReply')"/>
      </template>
    </van-nav-bar>
    <!-- 展示文章评论 -->
    <CommentItem :comment="comment"></CommentItem>
    <!-- 全部回复单元格 -->
    <van-cell title="全部回复"></van-cell>
    <!-- 回复列表 -->
    <CommentList
      ref="comment-list"
      :sourceId="comment.com_id"
      idType="c"
    ></CommentList>

    <!-- 底部区域 -->
    <div class="reply-bottom">
      <van-button
        size="small"
        round
        class="btn"
        @click="isPostShow = true"
      >写评论
      </van-button>
    </div>

    <!-- 评论提交弹框 -->
    <van-popup v-model="isPostShow" position="bottom">
      <CommentPost
        :targetId="comment.com_id"
        :artId="$route.params.articleId"
        @postSuccess="postSuccessFn"
      ></CommentPost>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import CommentPost from '@/views/article/components/comment-post'

export default {
  name: 'CommentReply',
  components: {
    CommentPost,
    CommentItem,
    CommentList
  },
  props: {
    comment: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      isPostShow: false // 写评论弹框状态
    }
  },
  methods: {
    // 发布评论成功后触发的方法
    postSuccessFn (newComment) {
      this.isPostShow = false
      this.$refs['comment-list'].addComment(newComment)
    }
  }
}
</script>

<style scoped lang="less">
.comment-reply-container {
  padding-bottom: 44px;

  .reply-bottom {
    position: fixed;
    bottom: 30px;
    left: 0;
    right: 0;
    height: 0;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .btn {
    width: 60%;
  }
}
</style>
